import React, { Component } from 'react';
import SelectedImage from '@/components/plugins/selectImage/SelectImage';
import { connect } from 'dva';

export default class ImageForm extends Component {
    componentDidMount() {
        this.showModal();
    }
    render() {
        return (
            <SelectedImage onRef={this.imgModal} multiple={true} cdnUrl={window.cdnUrl} selectImage={this.onImageChange} />
        );
    }
    imgModal = ref => {
        this.imgmodal = ref;
    };
    showModal = () => {
        this.imgmodal.handleShowModal();
    };
    OpenImageModal = () => {
        this.imgmodal.handleShowModal();
    };
    onImageChange = res => {
        const { callback } = this.props;
        let html = "";
        res.forEach(item => {
            let imgObj = { imageUrl: item.imageUrl, width: item.width, height: item.height };
            html += `<p class="${'xkd-richtext-img-small'}"><img src="${imgObj.imageUrl}"  style="width:${imgObj.width};hight:${imgObj.height};max-width:100%;" /></p>`
        });
        let imgInfo = {}

        imgInfo.html = html
        callback(imgInfo)
        this.imgmodal.handleModalVisible();
    };
}
